package sibots;

import interfaces.InterfaceServidor;

import java.awt.Point;
import java.util.ArrayList;

import jason.RoboJason;
import jason.ambiente.HZTeamEnv;

import java.rmi.RemoteException;
import fuzzy_system.database.Variaveis;
import fuzzy_system.database.DBAtaque.VA;

import robocode.HitRobotEvent;
import robocode.HitWallEvent;
import robocode.rescue.ConstantesExecucao;
import robocode.rescue.RoboInfo;
import sibots.HZRobo;

import net.sourceforge.jFuzzyLogic.FIS;
import net.sourceforge.jFuzzyLogic.rule.Rule;

public class HZRobo extends RoboJason {

	private FuzzyAtaque fa;
	private FuzzyDefesa fd;
	private String estrategia;
	public HZRobo(){
		fa = new FuzzyAtaque(this);
		fd = new FuzzyDefesa(this);
		estrategia = null;
	}
	@Override
	public void mainLoop() {
		
		if ( info.getAcao() != null){
			if(info.getAcao().equals(HZTeamEnv.actionAtk)){
			    fa.main();
			    estrategia = "Ataque";
			}
			else if (info.getAcao().startsWith(HZTeamEnv.actionBlqRobo)) {
				fd.setRoboBloqueado(info.getAcao());
				fd.main();
				estrategia = "Defesa";
			}
			
		}
		else{
			doNothing();
		}
		
	}
    @Override
    public void onHitWall(HitWallEvent event){
    	if(estrategia.equals("Ataque")){
    		fa.trataBatida(event.getBearing());
    	}
    	else{
    		double angulo = event.getBearing();
        	if (angulo > -90 && angulo <= 90){
                setBack(10);
            } else {
                setAhead(10);
            }
        	
        	execute();
    	}
    }
    @Override
    public void onHitRobot(HitRobotEvent event){
    	if(estrategia.equals("Ataque")){
    		fa.trataBatida(event.getBearing());
    	}else{
    		double angulo = event.getBearing();
        	if (angulo > -90 && angulo <= 90){
                setBack(10);
            } else {
                setAhead(10);
            }
        	
        	execute();
    	}
    }
	@Override
	public void setup() {
		// TODO Auto-generated method stub
		
	}
}